package com.nuc.thread.cas.atomicinteger;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author 诗酒趁年华
 * @version 1.0.0
 * @Description
 * @createTime 2021年07月12日 09:49:00
 */
public class Test1 {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(1);

        System.out.println(atomicInteger.incrementAndGet());//++i
        System.out.println(atomicInteger.getAndIncrement());//i++ 先读再加 i的值会被修改


        System.out.println(atomicInteger.getAndAdd(5));//先获取 再加5
        System.out.println(atomicInteger.get());//8

        System.out.println(atomicInteger.updateAndGet(e->e*2));//16
        System.out.println(atomicInteger.getAndUpdate(e -> e+4));
        System.out.println(atomicInteger.get());

    }
}
